#ifndef DATABASEVIEW_H
#define DATABASEVIEW_H

#include<QTreeWidget>

class DatabaseView: public QTreeWidget{
Q_OBJECT
public:
	DatabaseView(QWidget *parent);
	~DatabaseView();
	
	void populate(QList<QString> artists);
	void populate(const QString &artist, QList<QString> albums);
	void populate(const QString &artist, const QString &album, QList<QString> songs );
	
	bool rootPopulated()const;
	bool artistPopulated(const QString &artist)const;
	bool albumPopulated(const QString &artist, const QString &album)const;
	
	void ensureArtistsEqual(const QList<QString> &artists);
	void ensureAlbumsEqual(const QString &artist, const QList<QString> &albums);
	void ensureSongsEqual(const QString &artist, const QString &album, const QList<QString> &songs);
	
	QStringList mimeTypes()const;
	QMimeData *mimeData(const QList<QTreeWidgetItem*> its)const;
	void mousePressEvent(QMouseEvent *event);
	
	void removeSongWithPath(QString path);
signals:
	void requestPopulate()const;//Populate Artists
	void requestPopulate(const QString &artist)const;//Populate albums for artist
	void requestPopulate(const QString &artist, const QString &album)const;//Populate songs for artist/album
	void addToPlaylist(QList<QString> songUrls);
private slots:
	void slotItemExpanded(QTreeWidgetItem *item);
	void slotEditMetadata();
	void slotAddToPlaylist();
private:
	QTreeWidgetItem *m_root;
	
	short unsigned int _level(QTreeWidgetItem *item)const;
	QTreeWidgetItem *_getItem(const QString &artist, const QString &album = QString())const;
	void _ensureChildrenEqual(QTreeWidgetItem *parent, const QList<QString> &data, bool isSongData = false);
	void _insertChild(QTreeWidgetItem *parent, const QString &data, int index, bool isSongData);
	QList<QString> _getSongPaths(QTreeWidgetItem *item)const;
	QList<QUrl> _getSongUrls(QTreeWidgetItem *item)const;
	QList<QString> _selectedPaths()const;
// 	QList<QUrl> _selectedUrls()const;
	void _deleteIfChildless(QTreeWidgetItem *item)const;
};

#endif
